package com.leo.biz.service.pub;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by leo on 2016/8/6.
 */

public class SIC {
    public static  List<Float> MA(List<Float> objList,int dayNum)
    {
        List<Float> ret=new LinkedList<>();
        for(int i=0;i<objList.size();i++)
        {
            int beg=i-dayNum>=0?i-dayNum+1:0;
            int end=i;
            ret.add(AVG(objList,beg,end));
        }
        return ret;
    }
    public static  float AVG(List<Float> objlist,int beg,int end)
    {
        int count=0;
        float total=0;
        for(int i=beg;i<objlist.size()&&i<=end;i++)
        {
            count++;
            total=total+objlist.get(i);
        }
        return  Math.round(total*100/count)/Float.valueOf("100.0");
    }


}
